package org.giovanolli.mumi.controller.business;

import org.giovanolli.mumi.controller.AbstractController;
import org.giovanolli.mumi.controller.AbstractModel;
import org.giovanolli.mumi.entities.Title;
import org.giovanolli.mumi.entities.filter.TitleFilter;
import org.giovanolli.mumi.service.Service;
import org.giovanolli.mumi.service.TitleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller("titleController")
public class TitleController extends AbstractController<Title> {

	@Autowired
	private TitleService service;

	@Autowired
	private TitleModel model;

	@Override
	protected void bindEntityToModel() {
		Title editedTitle = model.getEditedEntity();
		model.setName(editedTitle.getName());
	}

	@Override
	protected void bindModelToEntity() {
		Title editedTitle = model.getEditedEntity();
		editedTitle.setName(model.getName().toUpperCase());
	}

	protected Class<Title> getEntityClass() {
		return Title.class;
	}

	@Override
	protected AbstractModel<Title> getModel() {
		return model;

	}

	@Override
	protected Service<Title> getService() {
		return service;
	}

	public void init() {
		super.init();
		model.setFilter(new TitleFilter());
	}
}
